<template>
  <div id="app">
    <router-view v-if="isRouterAlive" />
  </div>
</template>

<script>
import setting from "./setting";
import { InitEnvConfig } from "@/utils/use-config";
export default {
  data() {
    return {
      isRouterAlive: true,
    };
  },
  provide() {
    return {
      reload: this.reload,
    };
  },
  created() {
    if (localStorage.getItem("theme")) {
      document.body.setAttribute("theme", localStorage.getItem("theme"));
    }
    // 设置body灰度
    if (localStorage.getItem("grayscale")) {
      const number = localStorage.getItem("grayscale");
      document.body.style.filter = `grayscale(${parseInt(number)}%)`;
    }
    if (setting.defaultHome) {
      this.$store.dispatch("app/openMenu", setting.defaultHome);
    }
    InitEnvConfig(); // 初始化环境配置
  },
  mounted() {
    // 监听刷新
    this.$Bus.$on("reload", () => {
      console.log("刷新页面");
      location.reload();
    });
  },
  beforeDestroy() {
    // 移除监听
    this.$Bus.$off("reload");
    // this.$Bus.$off("outLogin");
  },
  methods: {
    reload() {
      this.isRouterAlive = false;
      this.$nextTick(() => {
        this.isRouterAlive = true;
      });
    },
  },
};
</script>

<style>
#app {
  width: 100%;
  height: 100%;
}
</style>
